<template>
  <el-dialog v-model="dialogShow" title="文本预览" class="log-text">
    <el-input v-model="text" type="textarea" />
    <template #footer>
      <el-button type="primary" @click="testClick">复制</el-button>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>
import type { Ref } from 'vue'
import { ElMessage } from 'element-plus'
const dialogShow = defineModel<boolean>('dialog')
const text = defineModel('text') as Ref<string>
function testClick() {
  navigator.clipboard
    .writeText(text.value)
    .then(() => {
      ElMessage.success('复制成功')
    })
    .catch(() => {
      ElMessage.error('复制失败')
    })
}
</script>

<style lang="less">
.log-text {
  height: 60vh;
  display: flex;
  flex-direction: column;
  .el-dialog__body {
    flex: 1;
    .el-textarea {
      height: 100%;
    }
    .el-textarea__inner {
      height: 100%;
      resize: none;
    }
  }
}
</style>
